// pages/commodity-details/commodity-details.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodsInfo:{},
    goodsInfoPic: {},
    host:app.globalData.host
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var goodsId = options.goodsId;
    wx.request({
      url: app.globalData.host + '/index/goodsDetail',
      method: "POST",
      data: { goods_id: goodsId },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res) {
        let data = res.data
        if (data.code == 2000){
          if (data.data[0].length > 0){
            data.data[0].forEach(function (e, i) {
              e.value = e.value.replace(/<br\/>/g, "\n")
            })
            that.setData({
              goodsInfo: data.data[0]
            })
          }
          that.setData({
            goodsInfoPic: data.data[1]
          })
        }else{
          app.showToastNone(data.msg);
        }
      }
    })
  },
})